<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <p data-lake-id="u6be87f06" id="u6be87f06"><span data-lake-id="u823b4a2b" id="u823b4a2b">所谓快照读，就是读取的是快照数据，即快照生成的那一刻的数据，像我们</span><strong><span data-lake-id="u6f9531f1" id="u6f9531f1">常用的普通的SELECT语句在不加锁情况下就是快照读。</span></strong><span data-lake-id="u4f6ae08f" id="u4f6ae08f">如：</span></p>
  <p data-lake-id="u1d0ba8bb" id="u1d0ba8bb"><br></p>
  <pre lang="java"><code>
SELECT * FROM xx_table WHERE ...
</code></pre>
  <p data-lake-id="ueb898db8" id="ueb898db8"><br></p>
  <p data-lake-id="u872f22e7" id="u872f22e7"><span data-lake-id="ue4008df4" id="ue4008df4">和快照读相对应的另外一个概念叫做当前读，当前读就是读取最新数据，所以</span><strong><span data-lake-id="u1e040aa2" id="u1e040aa2">，加锁的 SELECT，或者对数据进行增删改都会进行当前读</span></strong><span data-lake-id="u43f46c02" id="u43f46c02">，比如：</span></p>
  <p data-lake-id="ua463079a" id="ua463079a"><br></p>
  <pre lang="java"><code>
SELECT * FROM xx_table LOCK IN SHARE MODE;

SELECT * FROM xx_table FOR UPDATE;

INSERT INTO xx_table ...

DELETE FROM xx_table ...

UPDATE xx_table ...
</code></pre>
  <p data-lake-id="ucc418ba4" id="ucc418ba4"><br></p>
  <p data-lake-id="u4f248980" id="u4f248980"><span data-lake-id="u048f747a" id="u048f747a">在MySQL 中，</span><strong><span data-lake-id="u93ba8534" id="u93ba8534">只有READ COMMITTED 和 REPEATABLE READ这两种事务隔离级别才会使用快照读。</span></strong></p>
  <p data-lake-id="ue5a8ddff" id="ue5a8ddff"><span data-lake-id="udbfb7d13" id="udbfb7d13">​</span><br></p>
  <ul list="u5733b887">
   <li fid="uae11c7a2" data-lake-id="ubaee479c" id="ubaee479c"><strong><span data-lake-id="u9d8ac995" id="u9d8ac995">在 RR 中，快照会在事务中第一次SELECT语句执行时生成</span></strong><span data-lake-id="ua840b525" id="ua840b525">，只有在本事务中对数据进行更改才会更新快照。</span></li>
  </ul>
  <ul list="u9331435d">
   <li fid="u2ba44872" data-lake-id="u67481e04" id="u67481e04"><strong><span data-lake-id="u3e639105" id="u3e639105">在 RC 中，每次读取都会重新生成一个快照</span></strong><span data-lake-id="u75f209e1" id="u75f209e1">，总是读取行的最新版本。</span></li>
  </ul>
  <p data-lake-id="u12a901d4" id="u12a901d4"><br></p>
 </body>
</html>